import 'package:flutter/material.dart';

import '../../utils/tools/screenutil_tool.dart';

/// 弹窗类
/// * [confirmDialog] 确认类型弹窗
class Dialogs {
  /// 确认类型弹窗
  /// * [ct] context|必填|上下文
  /// * [title] String|选填|弹窗标题|默认：提示
  /// * [content] String|选填|弹窗内容|默认：需要执行吗
  /// * [cancelCallback] Func|选填|取消行为回调
  /// * [confirmCallback] Func|选填|确认行为回调
  static confirmDialog(ct,
      {String title = '提示',
      String content = '需要执行吗？',
      Function cancelCallback,
      Function confirmCallback}) async {
    var alertDialogs = await showDialog(
        context: ct,
        builder: (context) {
          return AlertDialog(
            title: Text('${title}', style: TextStyle(fontSize: ST.setsp(36))),
            content:
                Text('${content}', style: TextStyle(fontSize: ST.setsp(30))),
            actions: <Widget>[
              FlatButton(
                  child: Text("取消"),
                  onPressed: () => cancelCallback != null
                      ? cancelCallback()
                      : Navigator.pop(context, "cancel")),
              FlatButton(
                  child: Text("确定"),
                  onPressed: () => confirmCallback != null
                      ? confirmCallback()
                      : Navigator.pop(context, "yes")),
            ],
          );
        });
    return alertDialogs;
  }

  static alertDialog(ct,
      {String title = '提示', String content = '无需要任何操作', String confirmBtn = '确定',
        Function confirmCallback}) async {
    var alertDialogs = await showDialog(
        context: ct,
        builder: (context) {
          return AlertDialog(
            title: Text('${title}', style: TextStyle(fontSize: ST.setsp(36))),
            content:
                Text('${content}', style: TextStyle(fontSize: ST.setsp(30))),
            actions: <Widget>[
              FlatButton(
                  child: Text("$confirmBtn"),
                  onPressed: (){
                    if(confirmCallback!=null){
                      confirmCallback();
                    }
                    Navigator.pop(context, "cancel");
                  }),
            ],
          );
        });
    return alertDialogs;
  }
}
